# 国扶系统---年满70修改为无劳动能力
import time
from selenium import webdriver
from selenium.webdriver.common.by import By

# 提供键盘按键的支持，比如：RETURN, F1, ALT等
from selenium.webdriver.common.keys import Keys
import user

from utils import (
    captcha_processing,
    find_element_click,
    iselement,
    load_cookies,
)

driver = webdriver.Edge()
driver.maximize_window()
load_cookies(driver)

driver.get(user.User.domain1)
driver.find_element(By.ID, "username").send_keys(user.User.username)
driver.find_element(By.ID, "password").send_keys(user.User.password)

# 获取验证码保存识别
imgCode = driver.find_element(By.ID, "jcaptcha")
imgCode.screenshot("jcaptcha.jpg")
driver.find_element(By.ID, "jcaptcha_response").send_keys(captcha_processing())

# 登录
driver.find_element(By.ID, "loginBut").click()

# 判断是否跳转到了没有任何权限的页面
if iselement(driver, By.ID, "j_login_error"):
    driver.find_element(By.ID, "j_username").send_keys(user.User.username)
    driver.find_element(By.ID, "j_password").send_keys(user.User.password)
    driver.find_element(By.ID, "loginButton").click()
else:
    pass

# 依次点击相应链接
for i in user.param:
    if find_element_click(driver, By.LINK_TEXT, i):
        continue
    else:
        break

# 后续操作 pandas openyxl，xlrd，，操作excel

time.sleep(5)
